package com.hongye.consult.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author fyd
 * @email 2104371759@qq.com
 * @date 2022/4/27
 * @time 9:15
 */
@Configuration
public class MyThreadConfig {

    @Value("${hongyePool.corePoolSize}")
    public int corePoolSize;
    @Value("${hongyePool.maximumPoolSize}")
    public int maximumPoolSize;
    @Value("${hongyePool.keepAliveTime}")
    public Long keepAliveTime;

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        return new ThreadPoolExecutor(
                corePoolSize,
                maximumPoolSize,
                keepAliveTime,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
